package com.seven.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.seven.model.User;
import com.seven.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping(value = "/users")
@Api(value = "userController相关api")
public class UserController {

	//后端数据集合用户信息
	private static List<User> users = Collections.synchronizedList(new ArrayList<User>());
	/**
	 * @方法名: getUserList
	 * @描述: 获取用户列表
	 * @return List<User>
	 */
	@ApiOperation(value = "获取用户列表", notes = "获取用户列表")
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public List<User> getUserList() {
		return users;
	}
	/**
	 * 
	 * @方法名: addUserByEntity
	 * @描述: 增加用户信息，返回用户信息
	 * @param user
	 * @return User
	 */
	@ApiOperation(value = "增加用户信息", notes = "传递实体参数")
	@RequestMapping(value="addUserByEntity",method=RequestMethod.POST)
	public User addUserByEntity(User user) {
		users.add(user);
		return user;
	}
	/**
	 * @方法名: addUserByJSON
	 * @描述: 增加实体的信息，采用json传递数据
	 * @param user
	 * @return User
	 */
	@ApiOperation(value = "增加用户信息", notes = "传递实体参数JSON格式的参数")
	@RequestMapping(value="addUserByJSON",method=RequestMethod.POST)
	public User addUserByJSON(@RequestBody User user) {
		users.add(user);
		return user;
	}
	
	@Autowired
	private UserService userService;
	@RequestMapping("getUser")
	@ApiOperation(value="获取数据库的用户的信息",notes="获取用户列表")
	public List<User> listUser(){
		return userService.listUser();
	}
/*	*//**
	 * 
	 * @方法名: show
	 * @描述: 请求单个的用户的信息
	 * @param stuName
	 * @return String
	 *//*
	@RequestMapping(value = "/show", method = RequestMethod.POST)
	@ApiOperation(value = "获取单个的用户信息，根据用户名去获取", notes = "根据用户名去获取")
	public String show(
			@ApiParam(required = true, name = "name", value = "姓名") @RequestParam(name = "name", required = true) String stuName) {
		return "请求成功";
	}

	@RequestMapping(value = "/", method = RequestMethod.POST)
	@ApiOperation(value = "创建用户", notes = "根据User对象创建用户")
	// @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true,
	// dataType = "User")
	public String postUser(User user) {

		users.put(user.getId(), user);

		return "创建用户成功";
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public User getUser(@PathVariable Long id) {
		return users.get(id);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
	public String putUser(User user) {
		return "success";
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	public String deleteUser(@PathVariable Long id) {
		users.remove(id);
		return "success";
	}*/

}